package com.dengcj.ecology.request.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 流程表单处理类返回信息对象
 * @author dengchunjie
 * @date 2012-12-09
 */
public class NodeExecuterResult {

    public NodeExecuterResult(){

    }

    public NodeExecuterResult(String title){
        if(!"".equals(title)) {
            this.msgTitle = title;
        }
    }

    private boolean status = true;

    private String msgTitle = "NodeValidatorMsg未设置消息标题";

    private List<String> msgList = new ArrayList<>();

    private Object dataObject;

    public Object getData() {
        return dataObject;
    }

    public void setData(Object dataObject) {
        this.dataObject = dataObject;
    }


    public void setMsgTitle(String msgTitle) {
        this.msgTitle = msgTitle;
    }

    public String getMsgTitle() {
        return msgTitle;
    }

    public void addMsg(String msg){
        this.status = false;
        msgList.add(msg);
    }

    public boolean getStatus() {
        return status;
    }

    public void setFailed() {
        this.status = false;
    }

    public List<String> getMsgList(){
        return this.msgList;
    }

    public String getMsgHtml(){
        return msgList.stream().filter(msg -> !"".equals(msg)).map(msg -> "<li>"+msg+"</li>").collect(Collectors.joining());
    }

    @Override
    public String toString(){
        if(this.status){
            return "";
        }

        return this.msgTitle + "<br/>"+getMsgHtml();
    }
}
